import { Service } from 'egg';

export default class Test extends Service {
  // 给角色分配权限
  public async create(obj) {
    // const { roleId } = obj;
    try {
      const data = await this.ctx.model.RoleRights.create(obj);
      const userRoleData = data.dataValues;
      return userRoleData;
    } catch (e) {
      throw new Error('分配权限失败');
    }
  }
  // 移除角色的权限
  public async destroy(roleId, rightsId) {
    const data = await this.ctx.model.RoleRights.destroy({
      where: {
        roleId,
        rightsId,
      },
    });
    if (data <= 0) {
      throw new Error('移出权限失败');
    }
  }
}
